import Cookie from "js-cookie";
const count = {
  namespaced: true,
  state: {
    count: 0,
  },
  getters: {
    showCount: (state) => {
      return "当前最新的数量是【" + state.count + "】";
    },
  },
  mutations: {
    add(state) {
      state.count += 1;
    },
    addN(state, key) {
      state.count += key;
    },
    sub(state) {
      state.count -= 1;
    },
    subN(state, key) {
      state.count -= key;
    },
  },
  actions: {
    addAsync(context) {
      //  在action 中不能直接修改 state 中的数据
      //  必须通过 context.commit() 触发某个 mutation 才行
      setTimeout(() => {
        context.commit("add");
      }, 500);
    },
    addNAsync(context, key) {
      setTimeout(() => {
        context.commit("addN", key);
      }, 500);
    },
    subAsync(context) {
      setTimeout(() => {
        context.commit("sub");
      }, 500);
    },
    subNAsync(context, key) {
      setTimeout(() => {
        context.commit("subN", key);
      }, 500);
    },
  },
};
export default count;
